<?php
if (!empty($_POST['cp_save'])) {
	$this->options["excluded"] = $_POST['cp_excluded'];
	$this->options["leftpostnum"] = $_POST['cp_leftpostnum'];
	$this->options["rightpostnum"] = $_POST['cp_rightpostnum'];
	$this->options["loading"] = $_POST['cp_loading'];
	$this->options["loptions"] = $_POST['cp_loptions'];
	$this->options["closewidget"] = $_POST['cp_closewidget'];
	$this->options["logo"] = $_POST['cp_logo'];
	$this->options["social"] = $_POST['cp_social'];
	$this->options["featured"] = $_POST['cp_featured'];
	$this->options["featured_n"] = $_POST['cp_featured_n'];
	$this->options["feed_name"] = $_POST['cp_feed_name'];
	$this->options["recent_num"] = $_POST['cp_recent_num'];
	$this->options["viewed_num"] = $_POST['cp_viewed_num'];
	$this->options["discussed_num"] = $_POST['cp_discussed_num'];
	$this->options["videos"] = $_POST['cp_videos'];
	$this->options["videose"] = $_POST['cp_videose'];
	$this->options["leftcatsN"] = $_POST['cp_leftcatsN'];
	$this->options["rightcatsN"] = $_POST['cp_rightcatsN'];
	for ($i = 1; $i <= $_POST['cp_leftcatsN']; $i++) {
	$this->options["leftcats".$i] = $_POST['cp_leftcats'.$i];
	}
	for ($i = 1; $i <= $_POST['cp_rightcatsN']; $i++) {
	$this->options["rightcats".$i] = $_POST['cp_rightcats'.$i];
	}
	update_option($cpanel['name'], $this->options);
	echo '<div class="updated fade msg" id="message"><p>Your changes have been saved.</p></div>';
}

if (!empty($_POST['cp_save_logo'])) {

	if ($_FILES['logo_file']['name'] != 'logo.png') {
	echo '<div class="error" id="message"><p>Please enter a valid logo and use the format (logo.png) then try again.</p></div>';
	} else {
	$target_path = TEMPLATEPATH.'/styles/'.$this->options['style'].'/img/logo.png';
	if (move_uploaded_file($_FILES['logo_file']['tmp_name'], $target_path)) {
	echo '<div class="updated fade msg" id="message"><p>Logo has been uploaded successfully!</p></div>';
	} else {
	echo '<div class="error" id="message"><p>There was an error uploading the logo, please try again!</p></div>';
	}
	}

}
?>

<div class="cpage">
<h2>General Options</h2>

<?php if ($this->options['logo'] == 1) : ?>
<form enctype="multipart/form-data" action="" method="post">
<fieldset><legend>Blog Logo</legend>
<ul>
	<li><label>Current site logo</label></li>
	<li><img src="<?php bloginfo('template_directory'); ?>/styles/<?php print $this->options['style']; ?>/img/logo.png" alt="" /></li>
</ul>
<ul>
	<li><label>Upload logo from your PC (must be in the format: logo.png)</label></li>
	<li>
	<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
	<input type="file" name="logo_file" id="logo_file" value="" />
	<input type="submit" value="Upload File" name="cp_save_logo" id="cp_save_logo" class="button" style="color:#000" />
	</li>
</ul>
</fieldset>
</form>
<?php endif; ?>

<form action="" method="post">

<fieldset><legend>Appearance</legend>
<ul>
	<li><label for="cp_logo">Logo Type</label></li>
	<li>
	<select name="cp_logo" class="widefat mid">
	<option value="1"<?php selected(1, $this->options["logo"]); ?>>Image-based logo</option>
	<option value="0"<?php selected(0, $this->options["logo"]); ?>>Text-based logo</option>
	</select>
	</li>
</ul>
<ul>
	<li><label for="cp_loptions">Show Layout Options button</label></li>
	<li>
	<select name="cp_loptions" class="widefat chc">
	<option value="1"<?php selected(1, $this->options["loptions"]); ?>>Yes</option>
	<option value="0"<?php selected(0, $this->options["loptions"]); ?>>No</option>
	</select>
	</li>
</ul>
<ul>
	<li><label for="cp_loading">Preload content using JavaScript</label></li>
	<li>
	<select name="cp_loading" class="widefat chc">
	<option value="1"<?php selected(1, $this->options["loading"]); ?>>Yes</option>
	<option value="0"<?php selected(0, $this->options["loading"]); ?>>No</option>
	</select>
	</li>
</ul>
<ul>
	<li><label for="cp_social">Show social bookmarking buttons</label></li>
	<li>
	<select name="cp_social" class="widefat chc">
	<option value="1"<?php selected(1, $this->options["social"]); ?>>Yes</option>
	<option value="0"<?php selected(0, $this->options["social"]); ?>>No</option>
	</select>
	</li>
</ul>
<ul>
	<li><label for="cp_closewidget">Allow users to close widgets</label></li>
	<li>
	<select name="cp_closewidget" class="widefat chc">
	<option value="1"<?php selected(1, $this->options["closewidget"]); ?>>Yes</option>
	<option value="0"<?php selected(0, $this->options["closewidget"]); ?>>No</option>
	</select>
	<span>Set this to <strong>no</strong> to disable widget closing/collapsing.</span>
	</li>
</ul>
</fieldset>

<fieldset><legend>Features Setup</legend>
<ul>
	<li><label for="cp_featured_n">Number of posts to rotate in featured area</label></li>
	<li><input name="cp_featured_n" id="cp_featured_n" value="<?php echo $this->options["featured_n"]; ?>"  class="widefat num" /></li>
</ul>
<ul>
	<li><label for="cp_featured">Select featured category from the list</label></li>
	<li>
	<select name="cp_featured" class="widefat mid">
	<?php
	$cats = get_categories('hide_empty=0');
	foreach($cats as $cat) {
	?>
	<option value="<?php echo $cat->cat_ID; ?>"<?php selected($cat->cat_ID, $this->options["featured"]); ?>><?php echo $cat->cat_name; ?></option>
	<?php } ?>
	</select>
	</li>
</ul>
</fieldset>

<fieldset><legend>Left Column Categories</legend>
<ul>
	<li><label for="cp_leftcatsN">Number of categories that should be shown on left column</label></li>
	<li><input name="cp_leftcatsN" id="cp_leftcatsN" value="<?php echo $this->options["leftcatsN"]; ?>" class="widefat num" /></li>
</ul>
<ul>
	<li><label for="cp_leftpostnum">Number of featured posts in each category widget</label></li>
	<li><input name="cp_leftpostnum" id="cp_leftpostnum" value="<?php echo $this->options["leftpostnum"]; ?>" class="widefat num" /><span>Featured posts are the primary posts in the widget with thumbnails and excerpts.</span></li>
</ul>
<?php for ($i = 1; $i <= $this->options["leftcatsN"]; $i++) { ?>
<ul>
	<li><label for="cp_leftcats<?php echo $i; ?>">Category <?php echo $i; ?></label></li>
	<li>
	<select name="cp_leftcats<?php echo $i; ?>" class="widefat mid">
	<?php
	$cats = get_categories('hide_empty=0');
	foreach($cats as $cat) {
	?>
	<option value="<?php echo $cat->cat_ID; ?>"<?php selected($cat->cat_ID, $this->options["leftcats".$i]); ?>><?php echo $cat->cat_name; ?></option>
	<?php } ?>
	</select>
	</li>
</ul>
<?php } ?>
</fieldset>

<fieldset><legend>Right Column Categories</legend>
<ul>
	<li><label for="cp_rightcatsN">Number of categories that should be shown on right column</label></li>
	<li><input name="cp_rightcatsN" id="cp_rightcatsN" value="<?php echo $this->options["rightcatsN"]; ?>" class="widefat num" /></li>
</ul>
<ul>
	<li><label for="cp_rightpostnum">Number of featured posts in each category widget</label></li>
	<li><input name="cp_rightpostnum" id="cp_rightpostnum" value="<?php echo $this->options["rightpostnum"]; ?>" class="widefat num" /><span>Featured posts are the primary posts in the widget with thumbnails and excerpts.</span></li>
</ul>
<?php for ($i = 1; $i <= $this->options["rightcatsN"]; $i++) { ?>
<ul>
	<li><label for="cp_rightcats<?php echo $i; ?>">Category <?php echo $i; ?></label></li>
	<li>
	<select name="cp_rightcats<?php echo $i; ?>" class="widefat mid">
	<?php
	$cats = get_categories('hide_empty=0');
	foreach($cats as $cat) {
	?>
	<option value="<?php echo $cat->cat_ID; ?>"<?php selected($cat->cat_ID, $this->options["rightcats".$i]); ?>><?php echo $cat->cat_name; ?></option>
	<?php } ?>
	</select>
	</li>
</ul>
<?php } ?>
</fieldset>

<fieldset><legend>Other Settings</legend>
<ul>
	<li><label for="cp_excluded">Excluded categories from menu</label></li>
	<li><input name="cp_excluded" id="cp_excluded" value="<?php echo $this->options["excluded"]; ?>" class="widefat big" /><span>A comma seperated list of category IDs to exclude from main menu.</span></li>
</ul>
</fieldset>

<fieldset><legend>Video Setup</legend>
<ul>
	<li><label for="cp_videose">Enable Videos</label></li>
	<li>
	<select name="cp_videose" class="widefat chc">
	<option value="1"<?php selected(1, $this->options["videose"]); ?>>Yes</option>
	<option value="0"<?php selected(0, $this->options["videose"]); ?>>No</option>
	</select>
	</li>
</ul>
<ul>
	<li><label for="cp_videos">Select videos category from the list</label></li>
	<li>
	<select name="cp_videos" class="widefat mid">
	<?php
	$cats = get_categories('hide_empty=0');
	foreach($cats as $cat) :
	?>
	<option value="<?php echo $cat->cat_ID; ?>"<?php selected($cat->cat_ID, $this->options["videos"]); ?>><?php echo $cat->cat_name; ?></option>
	<?php endforeach; ?>
	</select>
	</li>
</ul>
</fieldset>

<fieldset><legend>Ajax Tabs Options</legend>
<ul>
	<li><label for="cp_recent_num">Number of recent stories to display</label></li>
	<li><input name="cp_recent_num" id="cp_recent_num" value="<?php echo $this->options["recent_num"]; ?>" class="widefat num" /></li>
</ul>
<ul>
	<li><label for="cp_viewed_num">Number of most viewed stories to display</label></li>
	<li><input name="cp_viewed_num" id="cp_viewed_num" value="<?php echo $this->options["viewed_num"]; ?>" class="widefat num" /></li>
</ul>
<ul>
	<li><label for="cp_discussed_num">Number of most discussed stories to display</label></li>
	<li><input name="cp_discussed_num" id="cp_discussed_num" value="<?php echo $this->options["discussed_num"]; ?>" class="widefat num" /></li>
</ul>
</fieldset>

<fieldset><legend>FeedBurner</legend>
<ul>
	<li><label for="cp_feed_name">FeedBurner Feed Name</label></li>
	<li><input name="cp_feed_name" id="cp_feed_name" value="<?php echo $this->options["feed_name"]; ?>" class="widefat mid" /></li>
</ul>
</fieldset>

<input type="submit" value="Update Settings" name="cp_save" class="button-primary" />
</form>

</div>